home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / Mozetta™ / Source / mozilla⁄cmd⁄macfe⁄utility / PrefControls.cp < prev   
Encoding:
Text File  |  1998-06-21  |  2.5 KB  |  84 lines  |  [TEXT/CWIE]

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #pragma mark ---CIntPrefPopup---
  20. //======================================
  21. class CIntPrefPopup
  22. // NOTE: There are two modes of operation: command mode and item mode.
  23. // Command mode happens if mNumCommands > 0, otherwise item mode obtains.
  24. // In item mode, unlike the base class LGAPopup, the values are zero based.  I.e., the
  25. // first menu item represents a pref value of zero.
  26. // In command mode, the command numbers of the items are used for the pref values,
  27. // allowing the menu items to represent non-consecutive pref values, or reordered
  28. // pref values.
  29. //======================================
  30. :    public LGAPopup
  31. ,    public MPreference<LControl,int32>
  32. {
  33. public:
  34.     CIntPrefPopup(LStream* inStream)
  35.         :    LGAPopup(inStream)
  36.         ,    MPreference<LControl,int32>(this, inStream)
  37.         {
  38.         }
  39.     virtual ~CIntPrefPopup()
  40.         {
  41.             WriteSelf();
  42.         }
  43.     enum { class_ID = 'Ppop' };
  44.     virtual void FinishCreateSelf()
  45.         {
  46.             LGAPopup::FinishCreateSelf();
  47.             MPreferenceBase::FinishCreate();
  48.         }
  49.     virtual int32 GetPaneValue() const
  50.         {
  51.             Int32 itemNumber = LGAPopup::GetValue();
  52.             // Use the command nums, if provided.
  53.             if (mNumCommands > 0)
  54.                 return (*mCommandNums)[itemNumber - 1];
  55.             // Otherwise, use the menu item number - 1 (it's zero based).
  56.             return itemNumber - 1;
  57.         }
  58.     virtual void SetPaneValue(int32 inData)
  59.         {
  60.             if (mNumCommands == 0)
  61.             {
  62.                 // Item mode.
  63.                 LGAPopup::SetValue(inData + 1); // first item's value is zero.
  64.             }
  65.             else
  66.             {
  67.                 // Command mode.
  68.                 CommandT* cur = *mCommandNums;
  69.                 for (int item = 1; item <= mNumCommands; item++, cur++)
  70.                 {
  71.                     if (*cur == inData)
  72.                     {
  73.                         SetValue(item);
  74.                         break;
  75.                     }
  76.                 }
  77.             }
  78.             WriteSelf();
  79.         }
  80.     void SetValue ( Int32 value ) { LGAPopup::SetValue(value); WriteSelf(); }
  81.     
  82. }; // class CIntPrefPopup
  83.  
  84.